﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace CSSAdriverapp
{
    /// <summary>
    /// Interaction logic for EditNotes.xaml
    /// </summary>
    public partial class EditNotes : Window
    {
        private int parameter;

        public EditNotes(int parameter)
        {
            InitializeComponent();
            this.parameter = parameter;
            SetUpBox();
        }

        public void SetUpBox()
        {
            DataClassesDataContext db = new DataClassesDataContext();
            Event thisevent = (from c in db.Events where c.ID == parameter select c).FirstOrDefault();
            notesTextBox.Text = thisevent.Notes; 
        }
        private void cancelButton_Click(object sender, RoutedEventArgs e)
        {
            
            this.Close();
        }

        private void saveButton_Click(object sender, RoutedEventArgs e)
        {
            EditEventNote(parameter, notesTextBox.Text); 
        }

        private void EditEventNote(int e, String comment)
        {
            DataClassesDataContext db = new DataClassesDataContext();
            // Query the database for the row to be updated.
            var query =
                from ev in db.Events
                where ev.ID == e
                select ev;
            // Execute the query, and change the column values
            // you want to change.
            foreach (Event ev in query)
            {
                ev.Notes = comment;
                // Insert any additional changes to column values.
            }

            // Submit the changes to the database.
            try
            {
                db.SubmitChanges();
                this.Close();
            }
            catch (Exception w)
            {
                Console.WriteLine(w);
                // Provide for exceptions.
            }
        }

    }
}
